home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: hkusuc.hku.hk!hkusua!h8716718
- From: h8716718@hkusua.hku.hk (Starry Hung)
- Subject: Problem Negating an Unsigned Char
- X-Nntp-Posting-Host: hkusua.hku.hk
- Message-ID: <Dnnros.Lq.0.-s@hkusuc.hku.hk>
- Sender: usenet@hkusuc.hku.hk
- Organization: The University of Hong Kong
- X-Newsreader: TIN [version 1.1 PL6]
- Date: Sat, 2 Mar 1996 21:00:27 GMT
-
- Hi,
-
- I have tested the following simple code on at least two C compilers,
- including the Borland C 3.1, and find that it consistently generates
- the same results. The experiment convinces me that I should do the
- coding in a little bit redundant way (add a casting), however, I can't
- convince myself why the language performs like this, should anybody
- kindly tell me the story?
-
- The code is like that:
-
- unsigned char a=0x11;
- unsigned char b=0xEE;
- int c=0;
-
- void main( void ) {
- if( a == ~b ) {
- c=1;
- }
- }
-
- The c remains unchange, while it changes to 1 if I cast the ~b to unsigned
- char as if( a == (unsigned char) ~b )
-
- I browse through the FAQ but can't find the related discussion,
- apologise if I overlook on the list.
-
-
- Starry Hung.
-